Skip to content

fix: Refactor REQUIRES_NEW transaction to isolated writer component - #149

Closed
huytran2005 wants to merge 4 commits into
mainfrom
fix/fix-transactional-propagation-requires-new-3174292140714559
Closed

huytran2005 wants to merge 4 commits into
mainfrom
fix/fix-transactional-propagation-requires-new-3174292140714559

Conversation

@huytran2005

Copy link
Copy Markdown
Contributor

Problem statement and rationale

The ExcursionReviewRepository had an overridden save method annotated with @Transactional(propagation = Propagation.REQUIRES_NEW). In Spring Data JPA, applying transactional boundaries directly on overridden repository interface methods can lead to the proxy ignoring the annotation and falling back to default propagation behavior. To properly enforce isolated transactions (especially to gracefully handle data integrity exceptions without rolling back the parent transaction), this logic must reside in a separate, injected Spring-managed service.

Summary of code and test changes

  • Created a new Spring-managed service ExcursionReviewWriter in cruise-activity-service with a method annotated with @Transactional(propagation = Propagation.REQUIRES_NEW).
  • Refactored ExcursionReviewService to delegate the review save operation to ExcursionReviewWriter instead of directly calling reviewRepository.save(review).
  • Removed the overridden save method from ExcursionReviewRepository.
  • Updated unit tests in ExcursionReviewAndAnalyticsTest to mock the newly introduced ExcursionReviewWriter dependency instead of ExcursionReviewRepository.

Verification commands executed and test results

Executed ./mvnw test and all 557 tests across all microservices passed successfully.
Code review confirmed the approach correctly addresses the Spring transactional proxy behavior issue.

Any residual limitations or human review recommendations

The manual injection of the mock dependency in the test setUp method works fine alongside @InjectMocks, but a human reviewer might choose to fully refactor the test to rely purely on either manual injection or fully rely on Mockito extensions for consistency.


PR created automatically by Jules for task 3174292140714559 started by @huytran2005

…mponent

- Fixed a bug where `@Transactional(propagation = Propagation.REQUIRES_NEW)` was applied to an overridden repository method `save` in `ExcursionReviewRepository`. Spring AOP often ignores annotations on repository interfaces in favor of the implementation class's default propagation.
- Created `ExcursionReviewWriter` to handle saving the review in an isolated transaction.
- Injected `ExcursionReviewWriter` into `ExcursionReviewService` to replace the direct repository save call.
- Updated `ExcursionReviewAndAnalyticsTest` to mock the new `ExcursionReviewWriter`.

Co-authored-by: huytran2005 <[email protected]>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

google-labs-jules Bot and others added 3 commits November 11, 2026 11:13
- Reverted an invalid `java-version: '25'` configuration in `.github/workflows/ci.yml` back to `'21'`. Java 25 is not supported and caused SonarQube analysis to fail with a 403 when downloading JRE metadata. Java 21 is the project's required LTS runtime.

Co-authored-by: huytran2005 <[email protected]>
- Reverted the hardcoded `if: false` skip condition on the SonarCloud analysis step in `.github/workflows/ci.yml`. Disabling quality gates is a security anti-pattern and violates project requirements.
- The step now correctly falls back to its original conditional check `if: env.SONAR_TOKEN != ''`. The 403 error is inherently resolved by ensuring Java 21 is correctly configured in the environment.

Co-authored-by: huytran2005 <[email protected]>
- Changed the `if` condition in `.github/workflows/ci.yml` from `if: env.SONAR_TOKEN != ''` to `if: ${{ env.SONAR_TOKEN != '' }}`.
- This ensures that if the SONAR_TOKEN secret evaluates to empty (e.g. in PRs from forks), the expression properly skips the SonarCloud analysis instead of inadvertently executing and causing a 403 Forbidden.

Co-authored-by: huytran2005 <[email protected]>
@huytran2005

Copy link
Copy Markdown
Contributor Author

Closing redundant draft PR created by automated bot.

@huytran2005
huytran2005 deleted the fix/fix-transactional-propagation-requires-new-3174292140714559 branch November 15, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant